//
//  ExSelectCaptureOrientationViewController.m
//  OC-Example
//
//  Created by apang on 2020/10/15.
//  Copyright © 2020 apang.men. All rights reserved.
//

#import "ExSelectCaptureOrientationViewController.h"
#import "ExCaptureViewController.h"

@interface ExSelectCaptureOrientationViewController ()

@end

@implementation ExSelectCaptureOrientationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];
    self.title = @"摄像头方向";
    
    UIButton * autoBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [autoBtn setTitle:@"Auto" forState:UIControlStateNormal];
    [autoBtn addTarget:self action:@selector(gotoNextVC:) forControlEvents:UIControlEventTouchUpInside];
    autoBtn.translatesAutoresizingMaskIntoConstraints = NO;
    autoBtn.tag = 1000;
    [self.view addSubview:autoBtn];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:autoBtn attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:autoBtn attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
    
    UIButton * topBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [topBtn setTitle:@"Top" forState:UIControlStateNormal];
    [topBtn addTarget:self action:@selector(gotoNextVC:) forControlEvents:UIControlEventTouchUpInside];
    topBtn.translatesAutoresizingMaskIntoConstraints = NO;
    topBtn.tag = 1001;
    [self.view addSubview:topBtn];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:topBtn attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[topBtn]-(10)-[autoBtn]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(topBtn,autoBtn)]];
    
    UIButton * bottomBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [bottomBtn setTitle:@"Bottom" forState:UIControlStateNormal];
    [bottomBtn addTarget:self action:@selector(gotoNextVC:) forControlEvents:UIControlEventTouchUpInside];
    bottomBtn.translatesAutoresizingMaskIntoConstraints = NO;
    bottomBtn.tag = 1003;
    [self.view addSubview:bottomBtn];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:bottomBtn attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[autoBtn]-(10)-[bottomBtn]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(bottomBtn,autoBtn)]];
    
    
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [leftBtn setTitle:@"Left" forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(gotoNextVC:) forControlEvents:UIControlEventTouchUpInside];
    leftBtn.translatesAutoresizingMaskIntoConstraints = NO;
    leftBtn.tag = 1002;
    [self.view addSubview:leftBtn];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:leftBtn attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[leftBtn]-(10)-[autoBtn]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(leftBtn,autoBtn)]];
    
    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    [rightBtn setTitle:@"Right" forState:UIControlStateNormal];
    [rightBtn addTarget:self action:@selector(gotoNextVC:) forControlEvents:UIControlEventTouchUpInside];
    rightBtn.translatesAutoresizingMaskIntoConstraints = NO;
    rightBtn.tag = 1004;
    [self.view addSubview:rightBtn];
    [self.view addConstraint:[NSLayoutConstraint constraintWithItem:rightBtn attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[autoBtn]-(10)-[rightBtn]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(rightBtn,autoBtn)]];
}

-(void)gotoNextVC:(UIButton *)sender {
    Orientation orientation = OrientationPortrait;
    switch (sender.tag) {
        case 1000:
            orientation = OrientationUnknown;
            break;
        case 1001:
            orientation = OrientationPortrait;
            break;
        case 1002:
            orientation = OrientationLandscapeLeft;
            break;
        case 1003:
            orientation = OrientationPortraitUpsideDown;
            break;
        case 1004:
            orientation = OrientationLandscapeRight;
            break;
            
        default:
            break;
    }
    ExCaptureViewController * captureVC = [[ExCaptureViewController alloc] init];
    captureVC.orientation = orientation;
    [self presentViewController:captureVC animated:YES completion:nil];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
